<?php

class UserModel extends Model{
	
	public function get_address_list($user_id){		
		$sql	=	"
					SELECT a1.*,b1.region_name province_name,b2.region_name province_name,b3.region_name city_name,b4.region_name district_name FROM `ybr_user_address`  a1
					left join ybr_region b1 on b1.region_id = a1.country
					left join ybr_region b2 on b2.region_id = a1.province
					left join ybr_region b3 on b3.region_id = a1.city
					left join ybr_region b4 on b4.region_id = a1.district
					WHERE a1.user_id = '{$user_id}'
					";
		return M()->query($sql);
	}
	
	public function del_address_byId($address_id,$user_id = 0){
		$sql = "delete from `ybr_user_address` where address_id='{$address_id}' and user_id ='{$user_id}'";		
		return M()->execute($sql);
	}
	
	public function get_address_byid($address_id,$user_id){
		$sql	=	"
					SELECT a1.*,b1.region_name province_name,b2.region_name province_name,b3.region_name city_name,b4.region_name district_name FROM `ybr_user_address`  a1
					left join ybr_region b1 on b1.region_id = a1.country
					left join ybr_region b2 on b2.region_id = a1.province
					left join ybr_region b3 on b3.region_id = a1.city
					left join ybr_region b4 on b4.region_id = a1.district
					WHERE a1.user_id = '{$user_id}' and a1.address_id = '{$address_id}' 
					limit 1
					";
		$datas	=	M()->query($sql);
		return empty($datas) ? array() : $datas[0];
	}
	
	
	
}























